<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        #container{
            width: 300px;
            height: 200px;
            border:solid red 1px;
        }
    </style>
</head>
<body>
    <p>目标：将用一张图片拖放到一个div中</p>
    <img id="image" src="images/image.jpg" draggable="true" ondragstart="drag(event)">
    <div id="container" ondrop="drop(event)" ondragover="allowDrop(event)"></div>
    <script>
        function allowDrop(e){
            console.log('allowDrop',e)
            e.preventDefault()
        }

        function drag(e){
            console.log('drag',e)    
            e.dataTransfer.setData("Text",e.target.id)        
        }

        function drop(e){
            console.log('drop',e) 
            e.preventDefault()  
            let id = e.dataTransfer.getData("Text")   
            e.target.appendChild(document.getElementById(id))    
        }
    </script>
</body>
</html>